﻿<UserControl
	x:Class="EyeSoft.Demo.FiscalCode.Wpf.Views.FiscalCode"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:viewModels="clr-namespace:EyeSoft.Demo.FiscalCode.Wpf.ViewModels"
	xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
	xmlns:wpf="clr-namespace:EyeSoft.Demo.FiscalCode.Wpf">
	<UserControl.Resources>
		<wpf:StringToDateConverter x:Key="StringToDateConverter" />
		<DataTemplate x:Key="FiscalCodeTemplate" DataType="viewModels:FiscalCodeViewModel">
			<Grid>
				<Grid.RowDefinitions>
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
				</Grid.RowDefinitions>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="258" />
				</Grid.ColumnDefinitions>
				<Label Grid.Row="0" Grid.Column="0" Content="Firstname"/>
				<Label Grid.Row="1" Grid.Column="0" Content="Lastname"/>
				<Label Grid.Row="2" Grid.Column="0" Content="Town" HorizontalAlignment="Right"/>
				<TextBox Text="{Binding FirstName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true}" Grid.Column="1" Grid.Row="0" />
				<TextBox Text="{Binding LastName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true}" Grid.Column="1" Grid.Row="1" />
				<controls:AutoCompleteBox
					Text="{Binding TownSearch, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true}"
					MinimumPrefixLength="2"
					IsTextCompletionEnabled="True"
					ItemsSource="{Binding Towns}" 
					Grid.Column="1" Grid.Row="2" 
				/>
				<StackPanel Grid.ColumnSpan="2" Grid.Row="3" Orientation="Vertical" Margin="0,3,0,0">
					<StackPanel Orientation="Horizontal">
						<StackPanel Margin="3,0,0,0" Orientation="Horizontal">
							<Label Content="Birthdate"/>
							<DatePicker 
								SelectedDate="{Binding Birthdate}"
								Width="112"
							/>
						</StackPanel>
						<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
							<Label Content="Sex"/>
							<ComboBox Width="80" SelectedIndex="{Binding Sex, UpdateSourceTrigger=PropertyChanged}">
								<ComboBoxItem Content="Male" IsSelected="True"/>
								<ComboBoxItem Content="Female"/>
							</ComboBox>
						</StackPanel>
					</StackPanel>
					<TextBlock Margin="0,10,0,0" Text="Fiscal code" />
					<TextBox
						HorizontalContentAlignment="Center"
						FontSize="18"
						Foreground="Green"
						Text="{Binding FiscalCode, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
						IsReadOnly="True"
					/>
				</StackPanel>
			</Grid>
		</DataTemplate>
	</UserControl.Resources>
	<ContentControl Content="{Binding}" ContentTemplate="{StaticResource FiscalCodeTemplate}" />
</UserControl>